const { ccclass, property } = cc._decorator;

@ccclass
export default class TypeText extends cc.Component {

    @property(cc.Label)
    lab: cc.Label = null;

    onLoad() {
        const texts = ["帮我搞💰", "分享快乐✅"];

        let str = "";
        for (let i = 0; i < texts[0].length; i++) {
            str += texts[0].charAt(i);
            this.scheduleOnce(this._updateText.bind(this, str), .1 * i);
        }
        this.scheduleOnce(() => {
            for (let i = 0; i < texts[0].length; i++) {
                str = str.substring(0, str.length - 1);
                this.scheduleOnce(this._updateText.bind(this, str), .05 * i);
            }
            this.scheduleOnce(() => {
                for (let i = 0; i < texts[1].length; i++) {
                    str += texts[1].charAt(i);
                    this.scheduleOnce(this._updateText.bind(this, str), .1 * i);
                }
            }, .05 * texts[0].length);
        }, .1 * texts[0].length + 1);
    }

    start() {

    }

    _updateText(str: string) {
        this.lab.string = str;
    }

}